package com.sky.controller.setmeal;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.Result;
import com.sky.service.SetmealServise;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐相关接口")
public class SetmealController {
    @Autowired
    private SetmealServise setmealServise;

    //修改套餐
    @PutMapping
    @ApiOperation("修改套餐")
    public Result startOrStop(@RequestBody SetmealDTO setmealDTO) {
        setmealServise.updateSetmeal(setmealDTO);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("套餐分页查询")
    public Result pageQuery(SetmealPageQueryDTO setmealPage) {
        return Result.success(setmealServise.pageQuery(setmealPage));
    }

    @PostMapping("/status/{status}")
    @ApiOperation("套餐起售停售")
    public Result startOrStop(@PathVariable Integer status, Long id) {
        setmealServise.setmealStartOrStop(status, id);
        return Result.success();
    }


    @DeleteMapping()
    @ApiOperation("套餐批量删除")
    public Result deleteSetmeal(@RequestParam("ids") List<Long> ids) {
        setmealServise.deleteSetmeal(ids);
        return Result.success();
    }

    @PostMapping
    @ApiOperation("新增套餐")
    public Result addSetmeal(@RequestBody SetmealDTO setmealDTO) {
        setmealServise.addSetmeal(setmealDTO);
        return Result.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐")
    public Result list(@PathVariable Long id) {
        return Result.success(setmealServise.selectById(id));
    }





}
